<?php

include_once ( "AbstractDAO.php" );


class EventDAO extends AbstractDAO 
{
	
	
	public function GetEventActivities(&$shopDAO,&$productDAO,&$listDAO,$count='20')
	{
		global $platformList,$linkColorList;
		
		$cacheManager = GetCacheManager();
		$re = $cacheManager->Get( "getEventActivities_".$count, CNS_EVENT_ACTIVITIES );
		
		if( $re != false )
			return $re;

			
		$sql="select ue.user_id, ue.action, ue.parameters,ubi.nick from user_event as ue, user_basic_info as ubi 
			where ubi.id=ue.user_id and ue.action not in(10, 12, 32) order by rand() desc limit 0, $count";
		
		$result = $this->db->GetPlan($sql);
	
		$count =  count($linkColorList);
		
		if($result)
		{
			shuffle($result);
			foreach($result as $key=>$event)
			{
				$action = explode(',',$event['action']);
				
				$num = rand(0,$count-1);//随机选个颜色
							
				switch ($action[0])
				{
					
					case CREATE_LIST:
					{
						$list=$listDAO->GetListByLid($event['parameters']);
						$event['html']='<a class="ea" style="color:'.$linkColorList[$num].'"  href="'.edp_href_link(PAGENAME_USER_INFO, 'uid='.$event['user_id']).'">'.$event['nick'].'</a> 创建了评单 <a class="ea" style="color:'.$linkColorList[$num].'"  href="'.edp_href_link(PAGENAME_LIST_INFO,'lid='.$event['parameters']).'">'.$list['title'].'</a>。';
						break;
					}
					case COLLECT_LIST:
					{
						$list=$listDAO->GetListByLid($event['parameters']);
						$event['html']='<a class="ea" style="color:'.$linkColorList[$num].'"  href="'.edp_href_link(PAGENAME_USER_INFO, 'uid='.$event['user_id']).'">'.$event['nick'].'</a> 收藏了评单 <a class="ea" style="color:'.$linkColorList[$num].'"  href="'.edp_href_link(PAGENAME_LIST_INFO,'lid='.$event['parameters']).'">'.$list['title'].'</a>。';
						break;
					}				
	
					case ADD_SHOP:
					{						
						$shopInfo=$shopDAO->GetShopInfo($event['parameters']);
						$shopName = EdpStrLen($shopInfo['shop_name'])<20?$shopInfo['shop_name']:EdpSubStr($shopInfo['shop_name'], '0', '20').'...';						
						
						$platid=$shopInfo['plat_id'];
						$platform = (intval($platid)<100)?'店铺':'商城';			
						
						$event['html']='<a class="ea" style="color:'.$linkColorList[$num].'"  href="'.edp_href_link(PAGENAME_USER_INFO, 'uid='.$event['user_id']).'">'.$event['nick'].'</a> 添加了'.$platform.' <a class="ea" style="color:'.$linkColorList[$num].'"  href="'.edp_href_link(PAGENAME_SHOP_INFO,'sid='.$event['parameters']).'">'.$shopName.'</a>。';
						
						break;
					}
//					case ADD_PRODUCT:
//					{
//						$idlist=preg_split('/\s/',$event['parameters']);
//						
//						$shopInfo=$shopDAO->GetShopInfo($idlist['0']);
//						$shopName = EdpStrLen($shopInfo['shop_name'])<20?$shopInfo['shop_name']:EdpSubStr($shopInfo['shop_name'], '0', '20').'...';		
//
//						$platid=$shopInfo['plat_id'];
//						$platform = (intval($platid)<100)?'店铺':'商城';
//						
//						$product=$productDAO->GetProductInfo($idlist['1']);							
//						$productName = EdpStrLen($product['product_name'])<40?$product['product_name']:EdpSubStr($product['product_name'], '0', '40').'...';
//						
//						$event['html']='<a class="ea" style="color:'.$linkColorList[$num].'"  href="'.edp_href_link(PAGENAME_USER_INFO, 'uid='.$event['user_id']).'">'.$event['nick'].'</a> 添加了'.$platform.' <a class="ea" style="color:'.$linkColorList[$num].'"  href="'.edp_href_link(PAGENAME_SHOP_INFO,'sid='.$idlist['0']).'">'.$shopName.'</a> 的商品 <a class="ea" style="color:'.$linkColorList[$num].'"  href="'.edp_href_link(PAGENAME_PRODUCT_INFO,'pid='.$idlist['1']).'">'.$productName.'</a>。';

//						break;
//					}
					case COLLECT_SHOP:
					{
						$shopInfo=$shopDAO->GetShopInfo($event['parameters']);
						$shopName = EdpStrLen($shopInfo['shop_name'])<20?$shopInfo['shop_name']:EdpSubStr($shopInfo['shop_name'], '0', '20').'...';						
						
						$platid=$shopInfo['plat_id'];
						$platform = (intval($platid)<100)?'店铺':'商城';
						
						$event['html']='<a class="ea" style="color:'.$linkColorList[$num].'"  href="'.edp_href_link(PAGENAME_USER_INFO, 'uid='.$event['user_id']).'">'.$event['nick'].'</a> 收藏了'.$platform.' <a class="ea" style="color:'.$linkColorList[$num].'"  href="'.edp_href_link(PAGENAME_SHOP_INFO,'sid='.$event['parameters']).'">'.$shopName.'</a>。';
						break;
					}
/*					case COLLECT_PRODUCT:
					{
						$idlist=preg_split('/\s/',$event['parameters']);
						$shopInfo=$shopDAO->GetShopInfo($idlist['0']);
						$shopName = EdpStrLen($shopInfo['shop_name'])<20?$shopInfo['shop_name']:EdpSubStr($shopInfo['shop_name'], '0', '20').'...';						

						$platid=$shopInfo['plat_id'];
						$platform = (intval($platid)<100)?'店铺':'商城';
												
						$product=$productDAO->GetProductInfo($idlist['1']);
						$productName = EdpStrLen($product['product_name'])<40?$product['product_name']:EdpSubStr($product['product_name'], '0', '40').'...';
						
						$event['html']='<a class="ea" style="color:'.$linkColorList[$num].'"  href="'.edp_href_link(PAGENAME_USER_INFO, 'uid='.$event['user_id']).'">'.$event['nick'].'</a> 收藏了'.$platform.' <a class="ea" style="color:'.$linkColorList[$num].'"  href="'.edp_href_link(PAGENAME_SHOP_INFO,'sid='.$idlist['0']).'">'.$shopName.'</a>的商品 <a class="ea" style="color:'.$linkColorList[$num].'"  href="'.edp_href_link(PAGENAME_PRODUCT_INFO,'pid='.$idlist['1']).'">'.$productName.'</a>。';
				
						break;
					}	*/
					case MODIFY_SHOP:
					{
						$shopInfo=$shopDAO->GetShopInfo($event['parameters']);
						$shopName = EdpStrLen($shopInfo['shop_name'])<20?$shopInfo['shop_name']:EdpSubStr($shopInfo['shop_name'], '0', '20').'...';						
						
						$platid=$shopInfo['plat_id'];
						$platform = (intval($platid)<100)?'店铺':'商城';							
						$event['html']='<a class="ea" style="color:'.$linkColorList[$num].'"  href="'.edp_href_link(PAGENAME_USER_INFO, 'uid='.$event['user_id']).'">'.$event['nick'].'</a> 修改了'.$platform.' <a class="ea" style="color:'.$linkColorList[$num].'"  href="'.edp_href_link(PAGENAME_SHOP_INFO,'sid='.$event['parameters']).'">'.$shopName.'</a> 的简介。';
						break;
					}	

									
					case NORMAL_REVIEW:
					{			
						$idlist=preg_split('/\s/',$event['parameters']);					
							
						$is_picture= '';
						$is_first='';						
					
						foreach($action as $k=>$value){
						
							if($value=='22'){							
								$is_picture = '<font color="red">[图]</font>';
							}else
							if($value=='21'){				
								$is_first = '第一次';
							}
						}					
						
//						if(isset($idlist[2])){
//							//存在product_id,表示是在product_info页面发表的点评，显示商品信息				
//							$productName=$productDAO->GetProductName($idlist[2]);
//							$productName = EdpStrLen($productName)<40?$productName:EdpSubStr($productName, '0', '40').'...';
//							
//							$event['html']='<a class="ea" style="color:'.$linkColorList[$num].'"  href="'.edp_href_link(PAGENAME_USER_INFO, 'uid='.$event['user_id']).'">'.$event['nick'].'</a> '.$is_first.'点评了商品 <a class="ea" style="color:'.$linkColorList[$num].'"  href="'.edp_href_link(PAGENAME_PRODUCT_INFO,'pid='.$idlist[2]).'">'.$productName.'</a>。'.$is_picture;
//							
//						}else{						
							//不存在product_id,表示是在shop_info页面发表的点评，显示店铺信息
							$shopInfo=$shopDAO->GetShopInfo($idlist[0]);	
							$shopName = (EdpStrLen($shopInfo['shop_name'])<20)?$shopInfo['shop_name']:(EdpSubStr($shopInfo['shop_name'], '0', '20').'...');						
							
							$platid=$shopInfo['plat_id'];							
							if(intval($platid)<100){								
								$event['html']='<a class="ea" style="color:'.$linkColorList[$num].'"  href="'.edp_href_link(PAGENAME_USER_INFO, 'uid='.$event['user_id']).'">'.$event['nick'].'</a> '.$is_first.'点评了 <a class="ea" style="color:'.$linkColorList[$num].'"  href="'.edp_href_link(PAGENAME_PLATFORM, 'platid='.$platid).'">'.$platformList["$platid"].'</a> 店铺 <a class="ea" style="color:'.$linkColorList[$num].'"  href="'.edp_href_link(PAGENAME_SHOP_INFO,'sid='.$idlist[0]).'">'.$shopName.'</a> [掌柜：<a class="ea" style="color:'.$linkColorList[$num].'"  href="'.edp_href_link(PAGENAME_SHOP_INFO,'sid='.$idlist[0]).'">'.$shopInfo['nick'].'</a>]。'.$is_picture;									
							}else {								
								$event['html']='<a class="ea" style="color:'.$linkColorList[$num].'"  href="'.edp_href_link(PAGENAME_USER_INFO, 'uid='.$event['user_id']).'">'.$event['nick'].'</a> '.$is_first.'点评了商城 <a class="ea" style="color:'.$linkColorList[$num].'"  href="'.edp_href_link(PAGENAME_SHOP_INFO,'sid='.$idlist[0]).'">'.$shopName.'</a>。'.$is_picture;																		
							}	

//						}
					
						break;
					}
										
					default:
					{
						//$event['html']='';
						break;
					}
				}
				if(isset($event['html']))
				$eventList[]=$event;
			}
			
			$re = $cacheManager->Set( "getEventActivities_".$count, $eventList, CNS_EVENT_ACTIVITIES );
			
			return $eventList;
		}

	}	
}

?>
